package main

import (
	"fmt"
	"github.com/gogf/gf/util/gconv"
	"math"
	"math/rand"
	"net/url"
	"strconv"
	"time"
)

type A struct {
}

func main() {
	//1.导入头文件 math/rand、time
	//2.添加随机数种子
	//3.使用随机数

	fmt.Println(time.Now().UnixNano())                             //时间戳/纳秒
	fmt.Println(time.Now().Unix())                                 //时间戳/秒
	fmt.Println(time.Now().YearDay())                              //一年的第多少天
	fmt.Println(time.Now().Second())                               //时间戳/秒
	fmt.Println("当前时间,", time.Now().Format("2006-01-02 15:04:05")) //当前时间, 2020-11-16 11:19:40

	rand.Seed(time.Now().UnixNano())
	for i := 0; i < 3; i++ {
		fmt.Println(rand.Intn(100)) // 0-99
	}

	fmt.Println(time.Now().Unix())

	data := map[int64]interface{}{
		1: struct{}{},
		2: struct{}{},
	}
	fmt.Println("data:", data)

	nowDate := time.Now().AddDate(0, 0, 1).Format("2006-01-02")
	fmt.Println("nowDate=", nowDate)

	price := 186.5 + 56
	priceInt, _ := strconv.Atoi(strconv.FormatFloat(price, 'f', 0, 64))
	fmt.Println(price, priceInt)

	fmt.Println(gconv.Int(10.85))

	fmt.Println("Decimal", Decimal(12.255))

	fmt.Println("Decimal1:", Decimal1(12.256))

	fmt.Println("Decimal2:", Decimal2(12.256))

	fmt.Printf("url.values : %T\n", url.Values{})

	var a *A
	fmt.Printf("a =%+v\n", a)

	fmt.Printf(" = %.1f\n", 100.25)

	urlParse(`shihuo://www.shihuo.cn?route=go&tpExtra={"fReqId":"8795FC330E822901867C8FB60C6481B4","fTp":"searchList:list:11","fTpName":""}&url=http://product.suning.com/0000000000/11755553485.html?dspm=4c813ec497db0721_eef0cc19507cbe37&fromShType=1&goodsType=7&openType=1&shopId=cn.suning.0000000000&tbBybt=1#{"from":"shihuo://www.shihuo.cn?route=goodsDetail","block":"Supplier","tp":"Supplier","sku_id":30870,"extra":"","dspm":"4c813ec497db0721_eef0cc19507cbe37","goods_id":"490136","supplier_id":"3190521","style_id":"2742112","size":"6G+128G","price":"1038","sort":"2","filter":"0000000"}`)
}

func Decimal(value float64) float64 {
	fmt.Println("Decimal func:", fmt.Sprintf("%.2f", value))
	value, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", value), 64)
	return value
}

func Decimal1(value float64) float64 {
	//return math.Trunc(value*1e2+0.5) * 1e-2 //4舍5入
	return math.Trunc(value*1e2) * 1e-2 //2位小数后直接抹掉
}

func Decimal2(value float64) float64 {
	//return math.Trunc(value*1e2+0.5) * 1e-2 //4舍5入
	return math.Trunc(value*1e2) * 1e-2 //2位小数后直接抹掉
}

func urlParse(urlString string) {
	u, _ := url.Parse(urlString)
	fmt.Println(u)
}
